﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;

namespace Budget.Core.DomainModel
{
    public class Balance : BaseEntity
    {
        public virtual decimal Amount { get; set; }

        public virtual decimal LostMoney { get; set; }

        public virtual DateTime CreationDate { get; set; }

        public virtual ICollection<OutcomeOrder> OutcomeOrders { get; protected set; }

        public virtual ICollection<IncomeOrder> IncomeOrders { get; protected set; } 

        public Balance()
        {
            OutcomeOrders = new Collection<OutcomeOrder>();
            IncomeOrders = new Collection<IncomeOrder>();
        }

        public virtual decimal CalculateBalance()
        {
            var income = IncomeOrders.Sum(io => io.Amount);
            var outcome = OutcomeOrders.Sum(oo => oo.Amount);
            return Amount + income - outcome;
        }
    }
}